using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FolderSync
{
	public partial class FolderPairDialog : Form
	{
		public FolderPairDialog()
		{
			InitializeComponent();
		}

		internal FolderPair FolderPair
		{
			get
			{
				FolderPair pair = new FolderPair();
				pair.Name = nameTextBox.Text;
				pair.LeftFolder = leftFolderTextBox.Text;
				pair.RightFolder = rightFolderTextBox.Text;
				return pair;
			}
			//set { folderPair = value; }
		}

		private void FolderPairDialog_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (DialogResult == DialogResult.OK) {
				if (FolderPairsManager.Instance.Contains(nameTextBox.Text)) {
					errorProvider.SetError(nameTextBox, "This name is already used, please select another.");
					e.Cancel = true;
				} else if (!System.IO.Directory.Exists(leftFolderTextBox.Text)) {
					errorProvider.SetError(leftFolderTextBox, "This folder is invalid.");
					e.Cancel = true;
				} else if (!System.IO.Directory.Exists(rightFolderTextBox.Text)) {
					errorProvider.SetError(rightFolderTextBox, "This folder is invalid.");
					e.Cancel = true;
				}
			}
		}

		private void leftBrowseButton_Click(object sender, EventArgs e)
		{
			if (leftFolderBrowserDialog.ShowDialog(this) == DialogResult.OK) {
				leftFolderTextBox.Text = leftFolderBrowserDialog.SelectedPath;
			}
		}

		private void rightBrowseButton_Click(object sender, EventArgs e)
		{
			if (rightFolderBrowserDialog.ShowDialog(this) == DialogResult.OK) {
				rightFolderTextBox.Text = rightFolderBrowserDialog.SelectedPath;
			}
		}
	}
}